package models;

import javax.persistence.*;

import controllers.Security;

import java.util.*;

import play.db.jpa.Model;
import play.data.validation.*;

@Entity
public class Customer extends Model {
	
	@Required
	@MinSize(value=5, message="Password must be at least 5 characters long")
	@MaxSize(value=50, message="Passwort cannot be longer that 50 chars")
	public String password;
	
	@OneToOne
	public Person person;
	@OneToOne
	public Address billingAddress;
	
	@ManyToMany
	public List<Person> friends;
	
	
	public Customer(String password, Person person, Address billingAddress) {
		super();
		this.password = password;
		this.person = person;
		this.billingAddress = billingAddress;
	}
	
	public static Customer findByEmail(String email) {
		Person pers = Person.find("byEmail", email).first();
		return Customer.find("byPerson", pers).first();
	}
	
	
}
